/**
 * @ClassName LC203
 * @Author ykx
 * @Date 2024/3/29 21:24
 * @Version 1.0
 */
public class LC203 {
    public static void main(String[] args) {
        LC203 lc203 = new LC203();
        int[] nums = new int[]{7, 7, 7, 7};
        ListNode listNode = ListNode.setData(nums);
        System.out.println(lc203.removeElements(listNode, 7));
    }

    public ListNode removeElements(ListNode head, int val) {
        head = new ListNode(0, head);
        ListNode dummyHead = head;
        while (head != null) {
            while (head.next != null && head.next.val == val) {
                head.next = head.next.next;
            }
            head = head.next;
        }

        return dummyHead.next;
    }
}
